package view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;

public abstract class AbstractStandartFrame extends JFrame 
{
	public AbstractStandartFrame(String title)
	{
		super(title);
		setSize(Globals.secondaryFrameSize);
	}

	/**
	 * This method adds standart finish/cancel buttons to the current frame
	 * @param N/A
	 */
	protected void addStandartButtons() 
	{
		Box tableBox = Box.createHorizontalBox();
		
		JButton finish = new JButton("Finish");
		finish.setToolTipText("Close and save changes");
		JButton cancel = new JButton("Cancel");
		cancel.setToolTipText("Close without saving changes");
		
		tableBox.add(finish);
		tableBox.add(cancel);
		
	    add(tableBox, BorderLayout.SOUTH);
	    
		/*Finish button listener - closes the frame and stores the changes */
		finish.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
			    try 
			    {
					finishAction();
			    } catch (NumberFormatException e)
			    {
			    	/* no action */
			    	return;
			    }
			}	  
		});
		  
		/*Cancel button listener - closes the frame*/
		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				dispose();		
			}	
		});
	}
		
	protected abstract void finishAction();
		
}
